package org.wutopia.labcloud.domain.order.controller;

import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.wutopia.labcloud.domain.order.controller.vo.input.OrderCreateOrderInputVO;
import org.wutopia.labcloud.domain.order.controller.vo.input.OrderGetListInputVO;
import org.wutopia.labcloud.domain.order.controller.vo.input.OrderPayInputVO;
import org.wutopia.labcloud.domain.order.controller.vo.output.OrderGetListOutputVO;
import org.wutopia.labcloud.domain.order.service.OrderService;
import org.wutopia.labcloud.library.common.base.CodedMessage;
import org.wutopia.labcloud.library.common.base.CommonResponse;
import org.wutopia.labcloud.library.common.base.PageInputVO;
import org.wutopia.labcloud.library.common.base.PageOutputVO;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/order")
public class OrderController {


    private OrderService orderService;

    @PostMapping("/list")
    public ResponseEntity<CodedMessage<PageOutputVO<List<OrderGetListOutputVO>>>> getOrderList(@RequestBody PageInputVO<OrderGetListInputVO> vo) {

        PageOutputVO<List<OrderGetListOutputVO>> list = orderService.getList(vo);

        return CommonResponse.successWithData(list);
    }

    @PostMapping("/create")
    public ResponseEntity<CodedMessage<String>> createOrder(@RequestBody OrderCreateOrderInputVO vo) throws Exception {

        orderService.createOrder(vo);

        return CommonResponse.success();
    }


    @PostMapping("/pay")
    public ResponseEntity<CodedMessage<String>> pay(@RequestBody OrderPayInputVO vo) throws Exception {

        orderService.pay(vo);

        return CommonResponse.success();
    }

    @PostMapping("/cancel")
    public ResponseEntity<CodedMessage<String>> cancel(@RequestBody Long orderId) throws Exception {

        orderService.cancel(orderId);
        return CommonResponse.success();
    }

    @PostMapping("/confirmed")
    public ResponseEntity<CodedMessage<String>> confirmed(@RequestBody Long orderId) throws Exception {

        orderService.cancel(orderId);
        return CommonResponse.success();
    }
}
